package contest.sweek203;

import java.util.Arrays;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/8/24 16:41
 */
public class Solution2 {

    public int maxCoins(int[] piles) {
        int res = 0;
        if (piles == null || piles.length == 0) return res;
        Arrays.sort(piles);
        int l = 0, r = piles.length - 1;
        while (l < r) {
            r--;
            l++;
            res += piles[r--];
        }
        return res;
    }
}
